package letcode1052

func MaxSatisfied(customers []int, grumpy []int, minutes int) int {

	s0 := 0
	s1, tmp := 0, 0

	for i, j := range grumpy {
		if j == 0 {
			s0 += customers[i]
		}
	}

	for right, value := range grumpy {
		if value == 1 {
			tmp += customers[right]
		}

		if right < minutes-1 {
			continue
		}

		if right > minutes-1 {
			out := right - minutes
			if grumpy[out] > 0 {
				tmp = tmp - customers[out]
			}
		}
		s1 = max(s1, tmp)
	}
	return s0 + s1
}
